#include<bits/stdc++.h>
using namespace std;
#define int long long

const int MOD = 998244353;


int f(vector<int> a, int x, int n, int m) {
	int sum = a[n];
	for (int i = n; i > 0; i--) {
		sum = sum * x % MOD + a[i - 1];
	}
	return sum % MOD;
}


signed main() {
//	system("start https://www.lanqiao.cn/problems/8036/learning/");

	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 0; i <= n; i++)
		cin >> a[i];

	int m;
	cin >> m;
	vector<int> x(m);
	for (int i = 0; i < m; i++)
		cin >> x[i];

	for (int i = 0; i < m; i++) {
		cout << f(a, x[i], n, m) << " ";
	}
	return 0;
}
